#define _CRT_SECURE_NO_WARNINGS
#include "ShellSort.h"

void ShellSort(int* arr, int size) {
	int gap = size;
	while (gap > 1) {
		gap = gap / 3 + 1;
		for (int i = 0; i < size - gap; i++) {
			int end = i;
			int tmp = arr[end + gap];
			while (end >= 0) {
				if (arr[end] > arr[end + gap]) {
					arr[end + gap] = arr[end];
					end -= gap;
				}
				else {
					break;
				}
			}
			arr[end + gap] = tmp;
		}
	}
}


int main() {
	int arr[] = { 2,3,4,51,4,51,1,2 };
	ShellSort(arr, sizeof(arr) / sizeof(arr[0]));
	for (int i = 0; i < (sizeof(arr) / sizeof(arr[0]));i++) {
		printf("%d ", arr[i]);
	}
	return 0;
}